/******************************************************************************
*	device/hid/mouse.h
*	 by Steve White
*
*	A light weight implementation of the USB protocol stack fit for a simple
*	driver.
*
*	device/hid/mouse.h contains definitions relating to mouses.
******************************************************************************/
#ifndef _DEVICE_HID_MOUSE_H
#define _DEVICE_HID_MOUSE_H

#include <usbd/device.h>
#include <types.h>

//------------------------------------------------------------------------------
// The DeviceDriver field in UsbDriverDataHeader for mouse devices.
//
#define DeviceDriverMouse  (0x4B424431)

//------------------------------------------------------------------------------
// The maximum number of buttons a mouse can report at once.
//
#define MouseMaxKeys  (6)  // Should be a multiple of 2

//------------------------------------------------------------------------------
// Names of mouse buttons
// These values are also used for bit masking in MouseGetButtonIsPressed()
//
typedef
	enum MouseDeviceButton {
		MouseDeviceButtonLeft   = 0x01,
		MouseDeviceButtonRight  = 0x02,
		MouseDeviceButtonMiddle = 0x04,
		MouseDeviceButtonSide   = 0x08,
		MouseDeviceButtonExtra  = 0x10,
	}
MouseDeviceButton;

//------------------------------------------------------------------------------
// Mouse specific data.
// The contents of the driver data field for mouse devices.
// Placed in HidDevice, as this driver is bult atop that.
//
typedef
	struct MouseDevice {
		UsbDriverDataHeader Header;        // Standard driver data header.
		u32                 Index;         // Internal - Index in mouse arrays.
		u8                  buttonState;
		s16                 mouseX;
		s16                 mouseY;
		s16                 wheel;
		HidParserReport     *MouseReport;  // The input report.
	}
MouseDevice;

//------------------------------------------------------------------------------
// Function prototypes
//
Result  MouseAttach (UsbDevice *device, u32 interface) ;

u32  MouseCount (void) ;

Result  MousePoll (u32 mouseAddress) ;

u32  MouseGetAddress (u32 index) ;

s16  MouseGetPositionX (u32 mouseAddress) ;

s16  MouseGetPositionY (u32 mouseAddress) ;

s16  MouseGetWheel (u32 mouseAddress) ;

u32  MouseGetPosition (u32 mouseAddress) ;

u8  MouseGetButtons (u32 mouseAddress) ;

bool MouseGetButtonIsPressed (u32 mouseAddress, MouseDeviceButton button) ;

#endif // _DEVICE_HID_MOUSE_H
